﻿using System;
using System.Runtime.Serialization;
using SharpObjects.Interfaces;

namespace SharpObjects.Instantiation
{
    [Serializable]
    [DataContract]
    public class TypeDescriptor : ITypeDescriptor
    {
        public TypeDescriptor(string assemblyPath = null, string typeName = null, params object[] arguments)
        {
            this.AssemblyPath = assemblyPath;
            this.TypeName = typeName;
            this.Type = null;
            this.Arguments = arguments;
        }

        [DataMember]
        public string AssemblyPath { get; set; }
        [DataMember]
        public string TypeName { get; set; }

        public Type Type { get; set; }

        [DataMember]
        public object[] Arguments { get; set; }

        public ITypeDescriptor Clone()
        {
            ITypeDescriptor typeDescriptor = new TypeDescriptor(this.AssemblyPath, this.TypeName, this.Arguments);

            if(this.Type != null)
            {
                typeDescriptor.Type = this.Type;
            }

            return typeDescriptor;
        }
    }
}
